<template>
  <div>
    <nav-bar>
      <template slot="left">
        <div class="back" @click="back">
          <img src="~assets/img/common/back.svg" alt="" />
        </div>
      </template>
      <template slot="center">
        <div class="title">
          <div
            v-for="(title, i) in titles"
            :key="i"
            class="title-item"
            :class="{ active: currentIndex === i }"
            @click="titleClick(i)"
          >
            {{ title }}
          </div>
        </div>
      </template>
    </nav-bar>
  </div>
</template>
<script>
import NavBar from "components/common/navBar/NavBar";
export default {
  name: "detailNavBar",
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    titleClick(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
    back() {
      this.$router.go(-1);
    },
  },
};
</script>
<style scoped>
.title {
  display: flex;
  font-size: 15px;
}
.title-item {
  flex: 1;
}
.back img {
  margin-top: 12px;
}
.active {
  color: var(--color-high-text);
}
</style>
